<template>
  <EduAliyunPlayer
    v-if="!loading"
    ref="exmaPlayer"
    :args="aplayer"
    @play="onPlayerPlay"
  ></EduAliyunPlayer>
</template>
<script>
import EduAliyunPlayer from '@/components/EduAliyunPlayer' // 播放器
const defaultProps = {
  id: 'exam-player-con', // 播放器外层容器的dom元素ID
  source: '', // 视频播放地址URL
  width: '370px', // 播放器宽度
  autoplay: false, // 播放器是否自动播放
  height: '208px', // 播放器高度
  format: 'm3u8', // 播放地址格式
  marquee: ['', { fontSize: '20px', color: '#FF920A' }, 'random'] // 跑马灯
}
export default {
  components: {
    EduAliyunPlayer
  },
  props: {
    fileurl: {
      type: String,
      default: ''
    },
    index: {
      type: Number,
      default: 0
    },
    palyIndex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      loading: true,
      aplayer: defaultProps
    }
  },
  watch: {
    palyIndex() {
      if (this.palyIndex != this.index) {
        if (this.$refs.exmaPlayer) {
          this.$refs.exmaPlayer.pause()
        }
      }
    }
  },
  methods: {
    onPlayerPlay() {
      this.$emit('play', this.index)
    }
  },
  mounted() {
    this.loading = true
    this.aplayer.source = this.fileurl
    this.loading = false
  }
}
</script>
